package com.example.yz.happywoker.listViewActivityRelevant;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.yz.happywoker.HistoryOrderActivity.MyAdapter;
import com.example.yz.happywoker.R;

import java.util.List;
import java.util.Map;

/**
 * Created by wangcheng on 2017/7/7.
 */

public class MyListViewAdapter extends BaseAdapter {

    private List<Map<String, Object>> list;
    private LayoutInflater layoutInflater;

    public MyListViewAdapter(Context context, List<Map<String, Object>> list) {
        super();
        this.list = list;
        //  this.layoutInflater=LayoutInflater.from(context);
        layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    /**
     * 组件集合，对应list.xml中的控件
     *
     * @author Administrator
     */
    class MyZujian {
        public TextView mytitle;
        public TextView mystate;
        public TextView mydate;
        public TextView myaddress;
        public TextView myworkContent;
    }

    @Override
    public int getCount() {
        return list.size();//根据他的返回值得到listView的长度

    }

    /**
     * 获得某一位置的数据
     */
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }
    /**
     * 获得唯一标识
     */
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyListViewAdapter .MyZujian zujian = null;
        if (convertView == null) {
            zujian = new MyListViewAdapter.MyZujian();
            //获得组件，实例化组件
            convertView = layoutInflater.inflate(R.layout.mylistview, null);
            zujian.mystate = (TextView) convertView.findViewById(R.id.mystate);
            zujian.mytitle = (TextView) convertView.findViewById(R.id.mytitlelist);
            zujian.mydate = (TextView) convertView.findViewById(R.id.mydateList);
            zujian.myaddress = (TextView) convertView.findViewById(R.id.myaddressList);
            zujian.myworkContent = (TextView) convertView.findViewById(R.id.myworkContent);
            convertView.setTag(zujian);
        } else {
            zujian = (MyListViewAdapter.MyZujian) convertView.getTag();
        }
        //绑定数据
        zujian.mystate.setText(list.get(position).get("Status").toString());
        zujian.mytitle.setText(list.get(position).get("RepairCategory").toString());
        zujian.mydate.setText(list.get(position).get("HandleTime").toString());
        zujian.myaddress.setText(list.get(position).get("RealAddress").toString());
        zujian.myworkContent.setText(list.get(position).get("ServiceContent").toString());
        return convertView;
    }

}

